package com.my.hotel.util;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

public class OssUtil {

    private static final String accessKeyId = "LTAI5tGm4x3zqxyNS7rWXznj";
    private static final String accessKeySecret = "y87UkrKQaETRdDFTxFgiD8AR8JIxY7";
    //bucket名称
    private static final String bucket = "my-oss-1313";
    private static String endpoint = "oss-cn-shanghai.aliyuncs.com";
    /*
        AccessKey ID LTAI5t8bPWJXejCURWcFFiMD
        AccessKey Secret yDnSHmIRNygd6gAaF0RsQBdZMndHBJ
        oss-cn-shanghai.aliyuncs.com
        my-oss-1314

        oss-cn-shanghai.aliyuncs.com
        LTAI5tGm4x3zqxyNS7rWXznj
        y87UkrKQaETRdDFTxFgiD8AR8JIxY7
     */
    public static Map<String, Object> upload(InputStream is, String fileName) {
        Map<String,Object> resultMap=new HashMap<String,Object>();
        try {
            OSS ossClient = new OSSClientBuilder().build("https://"+endpoint, accessKeyId, accessKeySecret);
            ossClient.putObject(bucket, fileName, is);
            ossClient.shutdown();
        } catch (Exception e) {
            e.printStackTrace();
        }
        String url="https://"  +  bucket+"."+endpoint+"/"+fileName;
        resultMap.put("fileName",url);
        return resultMap;
    }
}
